package com.gizwits.java;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

public class SendServer {

    private static final String EXCHANGE_NAME = "topic_logs_exchange";
    private  static  final String TOPTIC="topic";
    private static final  String[] routing_keys = new String[] { "log.info", "cron.warning",
            "auth.info", "kernel.critical" };
    Channel channel =null;
    public  SendServer()
    {
        try{
// 创建连接和频道
        ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("s5");
            factory.setPort(5672);
        Connection connection = factory.newConnection();


      channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, TOPTIC);



    } catch (Exception e) {
        e.printStackTrace();
    }
    }

    public    void  sendMesahe(String  json)
    {
        try {
            //MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish(EXCHANGE_NAME, "log.info", MessageProperties.PERSISTENT_TEXT_PLAIN, json.getBytes());
        }catch (Exception e) {
            e.printStackTrace();
        }


    }

}
